Monitor-Building Primitives

monitor primitives

The following functions can be used to construct monitors. A monitor so constructed has the type p4_monitor_t.

p4_moninit
\begin{example}
int p4_moninit(m,i)
p4_monitor_t *m;
int i;
\end{example}
initializes the monitor pointed to by m and gives it i queues for processes to wait on while they are blocked (see delay). One queue is sufficient for most purposes. The queues are numbered beginning with 0.

p4_menter
\begin{example}
VOID p4_menter(m)
p4_monitor_t *m;
\end{example}
enter the monitor pointed to by m. By the definition of a monitor, access is restricted to a single process in the monitor at a time (if everybody plays by the rules).

p4_mexit
\begin{example}
VOID p4_mexit(m)
p4_monitor_t *m;
\end{example}
exits the monitor pointed to by m. You are of course assumed to have previously entered that monitor.

p4_mcontinue
\begin{example}
VOID p4_mcontinue(m,i)
p4_monitor_t *m;
int i;
\end{example}
checks to see if there are any processes blocked on the i-th queue of the monitor m and causes one of them to be released for entry to the monitor if so. If there are no such processes, the invoking process simply exits. Note that a process could have been blocked previously by invoking the procedure p4_mdelay. The queues are numbered beginning with 0.

p4_mdelay
\begin{example}
VOID p4_mdelay(m,i)
p4_monitor_t *m;
int i;
\end{example}
permits a process to delay itself on the i-th queue of monitor m if the process wishes to release the monitor, but wants to be waked up by another process later (via the procedure p4_mcontinue). The queues are numbered beginning with 0.

Some Useful Monitors, ,Monitor-Building Primitives,Functions for Shared Memory